package priv.abadstring.study.haoke.webapi.manage.graphql;

import graphql.schema.DataFetchingEnvironment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import priv.abadstring.study.haoke.dubbo.entity.HouseResources;
import priv.abadstring.study.haoke.webapi.manage.HouseResourcesManage;
import priv.abadstring.study.haoke.webapi.vo.TableResult;

/**
 * HouseResourcesDataFetcher
 *
 * @author aBadString
 * @date 2021-06-18 14:05:37
 */
@Component
public class HouseResourcesListDataFetcher implements DataFetcherSpecification<TableResult<HouseResources>> {
    @Autowired
    private HouseResourcesManage houseResourcesManage;

    @Override
    public String fieldName() {
        return "HouseResourcesList";
    }

    @Override
    public TableResult<HouseResources> dataFetcher(DataFetchingEnvironment args) {
        Integer page = args.getArgument("page");
        if (page == null) {
            page = 1;
        }
        Integer pageSize = args.getArgument("pageSize");
        if (pageSize == null) {
            pageSize = 5;
        }
        return this.houseResourcesManage.list(null, page, pageSize);
    }
}
